/*
 * @Title: 反向拼团-票选优品
 * @Author: zhj
 * @Date:   2018-12-20
 * @Last Modified by:   zhj
 * @Last Modified time: 2018-12-20
 */
var dataInfo = new Object(),
	template = {
		init: function() {
			Vue.use(VueLazyload, {
				preLoad: 1.3,
				error: 'https://h5.meetao.com/img/product/init.png',
				loading: 'https://h5.meetao.com/img/product/init.png',
				attempt: 1
			});
			dataInfo.init = new Vue({
				el: '#app',
				data: {
					page: 2, //往期票选活动分页
					active: "", //最新活动期数
					barragePage: 1, //弹幕页数
					barrageLimit: 5, //弹幕一页展示多少条
					onnumLoading: false, //票选优品是否下来加载
					loading: false, //是否上拉加载
					isLoading: false, //是否下拉加载
					finished: false,//是否加载完成
					allData: false,//是否显示加载全部
					noData: true, //是否显示无数据状态
					pullShow:true,//是否显示票选优品
					thisNum: "", //选中当前期数
					numberList: [], //活动期数票选列表
					PastList: [], //往期票选活动列表
					stageList: [], //期数列表
					newstageList: [], //期数列表
					voteActivityMap: [], //当前活动信息
					barrageList: [], //弹幕数据
					bottowPopup: { //底部弹框
						shareShow: false, //分享弹框
						faceShow: false, //面对面扫码
					},
				},
				methods: {
					popup_close: function() { //关闭分享弹窗
						dataInfo.init.bottowPopup.shareShow = false;
					},
					voteClick: function(index, event) { //跳转票选详情
						var This = event.currentTarget,
							thisText = $(This).text();
						if(thisText == "去抢购" || thisText == "已投票去抢购") {
							window.location.href = "../html/productDetails.html?isFx=1&isPx=1&voteItemCode=" + dataInfo.init.numberList[index].code + "&productId=" + dataInfo.init.numberList[index].fxVirtualGoodsCode + '&voteItemNum=' + dataInfo.init.thisNum;
						} else {
							window.location.href = "../html/FPtVoteDetails.html?voteItemCode=" + dataInfo.init.numberList[index].code + '&inviterId=' + getQueryString('inviterId') + "&active=1";
						}
					},
					onLoad: function() { //更多票选优品上拉加载
						dataInfo.init.queryVoteActivityMoreList();
					},
					onNumberList: function() { //优品下拉加载
						dataInfo.init.numberList = [];
						setTimeout(function() {
							dataInfo.init.$toast('刷新成功');
							dataInfo.init.onnumLoading = false;
							dataInfo.init.getVoteForTheBestList();
						}, 500);
					},
					onRefresh: function() { //更多票选优品下拉刷新
						dataInfo.init.page = 2;
						dataInfo.init.PastList = [];
						dataInfo.init.allData = false;
						setTimeout(function() {
							dataInfo.init.$toast('刷新成功');
							dataInfo.init.queryVoteActivityMoreList();
						}, 500);
					},
					init: function() { //重置
						dataInfo.init.queryDefaultActivity(); //获取票选活动期数
						dataInfo.init.queryVoteActivityMoreList();
						//						dataInfo.init.queryBarrageList(); //查询弹幕数据
						if(getQueryString("needShare") == "1") {
							dataInfo.init.bottowPopup.shareShow = true;
							dataInfo.init.bottowPopup.faceShow = true;
						}
					},
					onRule: function() { //跳转规则
						window.location.href = "../html/FPtRule.html";
					},
					onThisVoteDetails: function(num) { //跳转该票选期详情
						window.location.href = "../html/FPtVoteGoodsDetails.html?activityIssueNum=" + num + '&inviterId=' + getQueryString('inviterId');
					},
					onVoteDetails: function(index, e) { //跳转投票详情
						window.location.href = "../html/FPtVoteDetails.html?voteItemCode=" + dataInfo.init.numberList[index].code + '&inviterId=' + getQueryString('inviterId');
					},
					//					queryBarrageList: function() { //查询票选优品的弹幕列表
					//						ajaxTemplate(addressTest + SERVICE.queryBarrageList, function(data) {
					//							if(data.tag == 0) {
					//								setInterval(function() {
					//
					//									dataInfo.init.barrageList = dataInfo.init.barrageList.concat(data.data.result);
					//									setTimeout(function() {
					//										for(var i in dataInfo.init.barrageList) {
					//											barrageWall.upWall(dataInfo.init.barrageList[i].robotHeadImageUrl, "", dataInfo.init.barrageList[i].robotNickname);
					//										}
					//									}, 1000);
					//								},5000);
					//							} else {
					//
					//							}
					//						}, {
					//							page: dataInfo.init.barragePage++,
					//							limit: "3"
					//						});
					//					},
					getThisNum: function(index, title) { //获取当前活动期数
						if(title == "更多") {
							dataInfo.init.queryVoteActivityMoreList();
						} else {
							dataInfo.init.thisNum = title.replace(/^[^\d]*(\d+)[^\d]*$/, "$1");
							dataInfo.init.getVoteForTheBestList();
						}
					},
					queryDefaultActivity: function() { //获取票选活动期数
						ajaxTemplate(addressTest + SERVICE.queryDefaultActivity, function(data) {
							if(data.tag == 0) {
								dataInfo.init.stageList = data.data.result;
								if(dataInfo.init.stageList.length == 0) {
									dataInfo.init.noData = true;
									dataInfo.init.pullShow = false;
								} else {
									dataInfo.init.noData = false;
									dataInfo.init.pullShow = true;
									setTimeout(function() {
										if(dataInfo.init.stageList.length < 7) {
											dataInfo.init.active = dataInfo.init.stageList.length - 1;
										} else {
											dataInfo.init.active = dataInfo.init.stageList.length;
										}
										for(var i in dataInfo.init.stageList) {
											dataInfo.init.newstageList.push(dataInfo.init.stageList[i].activityIssueNum);
										}
										dataInfo.init.thisNum = dataInfo.init.newstageList[dataInfo.init.newstageList.length - 1];
										dataInfo.init.getVoteForTheBestList(); //获取票选优品的列表
									}, 500)
								}
							} else {

							}
						}, {});
					},
					queryVoteActivityMoreList: function() { //获取更多的票选优品商品列表
						ajaxTemplate(addressTest + SERVICE.queryVoteActivityMoreList, function(data) {
							if(data.tag == 0) {
								console.log(data);
								dataInfo.init.PastList = dataInfo.init.PastList.concat(data.data.result);
								if(data.data.result.length < 7) {
									console.log("无数据");
									dataInfo.init.finished = true;
									dataInfo.init.allData = true;
								} else {
									console.log("有数据");
									dataInfo.init.finished = false;
								}
								dataInfo.init.loading = false;
								dataInfo.init.isLoading = false;
							} else {
								dataInfo.init.loading = false;
								dataInfo.init.finished = true;
								dataInfo.init.allData = true;
							}
						}, {
							page: dataInfo.init.page++
						});
					},
					getVoteForTheBestList: function() { //获取票选优品的列表
						ajaxTemplate(addressTest + SERVICE.getVoteForTheBestList, function(data) {
							if(data.tag == 0) {
								console.log(data);
								dataInfo.init.voteActivityMap = data.data.result.voteActivityMap;
								dataInfo.init.numberList = data.data.result.list;
								shareInfo.activityIssueNum = dataInfo.init.thisNum;
							} else {

							}
						}, {
							userId: userId,
							voteActivityIssueNum: dataInfo.init.thisNum
						});
					},
				},
			});
			dataInfo.init.init();
		}
	};
template.init();